Skip to content

Conversation

dt-atmosic
Copy link
Collaborator

@dt-atmosic dt-atmosic commented Sep 1, 2025

This PR implements issue #32 by adding new tools for artifact management and optimizing the getBuild response size.

New Tools Added

  1. getBuildArtifacts - Returns only the artifacts array from a build
    o Takes jobFullName and optional buildNumber parameters
    o Significantly reduces payload size compared to full getBuild response
    o Returns empty array for jobs without artifacts or non-existent jobs
    o Fixed JSON concatenation issue for top-level lists

  2. getBuildArtifact - Provides paginated access to individual artifact file contents
    o Supports offset/limit parameters for large files
    o Returns artifact content as text with pagination metadata
    o Includes safety limits to prevent excessive memory usage

Optimizations

  1. Modified getBuild response - Now excludes artifacts field
    o Created RunWithoutArtifactsSerializer to filter out artifacts
    o Updated JenkinsExportedBeanSerializerModifier to use custom serializer
    o Maintains all other build information while reducing response size

Testing done

  1. Comprehensive test coverage
    o BuildArtifactsExtensionTest - Integration tests for new tools
    o GetBuildWithoutArtifactsTest - Verifies getBuild optimization
    o BuildArtifactsExtensionCompileTest - Basic compilation verification

  2. Manual test
    o Augment Code MCP client w/ mvn hpi:run - Found JSON issue with top-level list
    o Manual test with Augment Code and production Jenkins server

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

dt-atmosic and others added 6 commits August 31, 2025 01:12
- Add BuildArtifactsExtension with getBuildArtifacts and getBuildArtifact tools
- Create RunWithoutArtifactsSerializer to exclude artifacts from getBuild responses
- Add comprehensive tests for new functionality
- Implement pagination support for large artifact files
- Maintain backward compatibility while reducing payload sizes

Addresses first part of issue jenkinsci#32: separate artifacts retrieval from build metadata
- Replace Java record with regular class for Java 11 compatibility
- Fix regex pattern in RunWithoutArtifactsSerializer with DOTALL flag
- Update test methods to use proper McpSchema.TextContent pattern
- Remove non-existent TestUtils.getTextContent() method calls
- Follow existing test patterns from the codebase
- Declare ObjectMapper inside lambda scope where it's used
- Resolves compilation error in GetBuildWithoutArtifactsTest.java
- Use record for BuildArtifactResponse
- Use TreePruner
- spotless:apply
@dt-atmosic dt-atmosic marked this pull request as ready for review October 20, 2025 23:20
@dt-atmosic dt-atmosic requested a review from a team as a code owner October 20, 2025 23:20
@dt-atmosic
Copy link
Collaborator Author

Working on the code coverage warnings.

@dt-atmosic dt-atmosic added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Oct 22, 2025
@dt-atmosic dt-atmosic requested review from olamy and topikachu October 22, 2025 23:14
Copy link
Member

@olamy olamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR.
the title says optimize getBuild response. is it remove artifacts from the tree?

* - "unchecked": Run.getArtifacts() returns raw List requiring unchecked conversion
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Tool(description = "Get the artifacts for a specific build or the last build of a Jenkins job")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need annotations = @Tool.Annotations(destructiveHint = false)
as it's true per default

.orElse(List.of());
}

@Tool(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need annotations = @Tool.Annotations(destructiveHint = false)
as it's true per default

offset = 0L;
}
if (limit == null || limit <= 0) {
limit = 65536; // 64KB default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better having a configuration (e.g SystemProperties) as users may want to configure more or less.

}

// Cap the limit to prevent excessive memory usage
final int maxLimit = 1048576; // 1MB max
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. should be configurable

}
// Serialize all results the same way - this fixes the JSON concatenation issue
// for top-level lists while maintaining proper JSON structure
resultBuilder.addTextContent(toJson(result));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. it's going to the direction of #82

} else {
resultBuilder.addTextContent(toJson(result));
}
// Serialize all results the same way - this fixes the JSON concatenation issue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need of this comment here.
it;s more a PR comment :)

}

// Convert to string (assuming text content)
String content = new String(buffer, 0, bytesRead, StandardCharsets.UTF_8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about binaries artifacts? (we can attach jar, war etc....)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants